﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Convertor
{
    class TemplateSplitNameConverter : IValueConverter
    {
        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return string.Empty;
            }
            else
            {
                string[] names = value.ToString().Split('-');

                if (parameter.Equals("Group"))
                {
                    if (names.Length == 1)
                    {
                        return string.Empty;
                    }
                    else
                    {
                        return names[0].Trim() + " - ";
                    }
                }
                else
                {
                    if (names.Length == 1)
                    {
                        return value;
                    }
                    else
                    {
                        return names[1].Trim();
                    }
                }
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
